 /*
 * @description: 店铺公告-老板审核专用
 * @Author: along
 * @Date: 2020-09-14
 * @Last Modified by: along
 * @Last Modified time: 2020-09-14
 */
<template>
    <div class="container shopNotice">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">公告标题:</p>
                    <el-input
                        v-model="formData.title"
                        placeholder="请输入内容"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">公告类型:</p>
                    <el-select
                        v-model="formData.type"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in typeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">公告状态:</p>
                    <el-select
                        v-model="formData.status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"/>
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">公告目标:</p>
                    <el-select
                        v-model="formData.scope"
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in scopeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
            </div>
            <!-- <div class="header-right">
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        :style="{fontWeight: '500'}"
                        @click="fnCreateNotice()"
                    >
                        新建公告
                    </el-button>
                </div>
            </div> -->
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="shopNotice"
        >
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="announce_title"
                label="公告标题"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="announce_type"
                label="公告类型"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.announce_type == 'system'">系统公告</p>
                    <p v-if="scope.row.announce_type == 'product'">产品公告</p>
                </template>
            </el-table-column>
            <el-table-column
                label="公告目标"
                align="left"
            >
                <template slot-scope="scope">
                    <span
                        v-for="(item, index) in scope.row.scope"
                        :key="index"
                    >
                        {{ item === 1 ? '商家后台' : '学生后台' }}
                        <span v-if="scope.row.scope.length === 2 && index === 0">，</span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column
                prop="edit_admin_name"
                label="编辑人"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="audit_status"
                label="审核状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.audit_status == 0">待提交</p>
                    <p v-if="scope.row.audit_status == 1">审核中</p>
                    <p v-if="scope.row.audit_status == -1">审核不通过</p>
                    <p v-if="scope.row.audit_status == 2">审核通过</p>
                </template>
            </el-table-column>
            <!-- <el-table-column
                prop="audit_reason"
                label="审核原因"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="create_time"
                label="创建时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column> -->
            <!-- <el-table-column
                prop="update_time"
                label="上次修改时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.update_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column> -->
            <!-- <el-table-column
                prop="publish_time"
                label="发布时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.publish_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column> -->
            <el-table-column
                label="操作"
                align="center"
            >
                <template slot-scope="scope">
                    <div class="button-flex">
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnCloseVerfy(scope.row)"
                            v-if="authResult.auth_audit"
                        >
                            拒绝
                        </el-button>
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnSendNotice(scope.row)"
                            v-if="authResult.auth_audit"
                        >
                            通过
                        </el-button>
                        <!-- <el-button
                            type="text"
                            class="curse-add"
                            @click="fnEditNotice(scope.row)"
                            v-if="!scope.row.publish_status"
                        >
                            编辑
                        </el-button> -->
                        <el-button
                            type="text"
                            class="curse-add"
                            @click="fnCheckNotice(scope.row)"
                        >
                            查看
                        </el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import { back } from '@/mixin/back';
export default {
    mixins: [back],
    components: {
        imgPreview
    },
    data () {
        return {
            formData: {
                title: '',
                type: '',
                status: 1,
                scope: 99
            },
            typeList: [
                {value: '',label: '全部'},
                {value: 'system',label: '系统公告'},
                {value: 'product',label: '产品公告'}
            ],
            statusList: [
                {value: '',label: '全部'},
                {value: 0,label: '待提交'},
                {value: 1,label: '审核中'},
                {value: -1,label: '审核不通过'},
                {value: 2,label: '审核通过'}
            ],
            scopeList: [
                {value: 99,label: '全部'},
                {value: 1,label: '商家后台'},
                {value: 2,label: '学生后台'}
            ],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {}
        };
    },
    filters: {},
    computed: {},
    watch: {},
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '商城'},{title: '店铺公告'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/hire_announce%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword: this.formData.title,
                announce_type: this.formData.type,
                audit_status: this.formData.status,
                scope: this.formData.scope
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 查看拒绝原因
         */
        fnCheckVerfy (row) {
            //
        },

        /**
         * @description 不通过
         */
        fnCloseVerfy (row) {
            this.$prompt('请输入拒绝原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /\S/,
                inputErrorMessage: '请输入拒绝原因'
            }).then(({ value }) => {
                this.$post('/student/hire_announce%5Caudit',{
                    announce_no: row.announce_no,
                    action: 'reject',
                    reason: value
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '拒绝成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * @description 提交审核
         */
        fnSubmitVerfy (row) {
            this.$confirm('此公告是否要提交审核?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/hire_announce%5Csubmit',{
                    announce_no: row.announce_no
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '提交成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * @description 发布公告
         */
        fnSendNotice (row) {
            this.$confirm('发布公告不可撤回,发布内容是否已经确定?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/hire_announce%5Caudit',{
                    announce_no: row.announce_no,
                    action: 'pass',
                    reason: ''
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '发布成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * @description 编辑公告
         */
        fnEditNotice (row) {
            this.$router.push({
                name: 'shopNoticeEdit',
                query: {
                    id: row.announce_no,
                    check: false
                }
            });
        },

        /**
         * @description 新建公告
         */
        fnCreateNotice (row) {
            this.$router.push({
                name: 'shopNoticeEdit',
                query: {
                    id: '',
                    check: false
                }
            });
        },

        /**
         * @description 查看公告
         */
        fnCheckNotice (row) {
            let routeData = this.$router.resolve({
                name: 'shopNoticeEdit',
                query: {
                    id: row.announce_no,
                    check: true
                }
            });

            window.open(routeData.href, '_blank');
        },

        /**
         * @description 查看图片
         * @param   {String}    images    单图预览
         * @param   {Array}     images     多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$notify({
                    title: '提示',
                    message: '图片类型错误',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .button-flex {
        display: flex;
        flex-direction: column;
        align-content: center;
    }
</style>
<style lang="less">
    .shopNotice{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .button-flex .el-button {
            padding: 4px 0;
            margin-left: 0px;
        }
    }
</style>
